package cloud.misiro.spring.cloud.registry;

import cloud.misiro.spring.cloud.MiniDiscoveryProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true)
public class MiniServiceRegistryAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public MiniDiscoveryProperties miniProperties() {
        return new MiniDiscoveryProperties();
    }

    @Bean
    public MiniRegistration miniRegistration(MiniDiscoveryProperties miniDiscoveryProperties) {
        return new MiniRegistration(miniDiscoveryProperties);
    }

    @Bean
    public MiniServiceRegistry miniServiceRegistry(MiniDiscoveryProperties miniDiscoveryProperties) {
        return new MiniServiceRegistry(miniDiscoveryProperties);
    }

    @Bean
    public MiniAutoServiceRegistration miniAutoServiceRegistration(ServiceRegistry<Registration> serviceRegistry, MiniRegistration miniRegistration) {
        return new MiniAutoServiceRegistration(serviceRegistry, miniRegistration);
    }
}
